home *** CD-ROM | disk | FTP | other *** search
/ Clickx 22 / Clickx 22.iso / DATA / eLibPro1.3_setup.exe / eLibPro.chm / rainbow.js < prev    next >
Encoding:
JavaScript  |  2004-08-06  |  7.6 KB  |  231 lines

  1. /************************************************************************/
  2. /* Rainbow Links Version 1.03 (2003.9.20)                               */
  3. /* Script updated by Dynamicdrive.com for IE6                           */
  4. /* Copyright (C) 1999-2001 TAKANASHI Mizuki                             */
  5. /* takanasi@hamal.freemail.ne.jp                                        */
  6. /*----------------------------------------------------------------------*/
  7. /* Read it somehow even if my English text is a little wrong! ;-)       */
  8. /*                                                                      */
  9. /* Usage:                                                               */
  10. /*  Insert '<script src="rainbow.js"></script>' into the BODY section,  */
  11. /*  right after the BODY tag itself, before anything else.              */
  12. /*  You don't need to add "onMouseover" and "onMouseout" attributes!!   */
  13. /*                                                                      */
  14. /*  If you'd like to add effect to other texts(not link texts), then    */
  15. /*  add 'onmouseover="doRainbow(this);"' and                            */
  16. /*  'onmouseout="stopRainbow();"' to the target tags.                   */
  17. /*                                                                      */
  18. /* This Script works with IE4,Netscape6,Mozilla browser and above only, */
  19. /* but no error occurs on other browsers.                               */
  20. /************************************************************************/
  21.  
  22.  
  23. ////////////////////////////////////////////////////////////////////
  24. // Setting
  25.  
  26. var rate = 20;  // Increase amount(The degree of the transmutation)
  27.  
  28.  
  29. ////////////////////////////////////////////////////////////////////
  30. // Main routine
  31.  
  32. if (document.getElementById)
  33. window.onerror=new Function("return true")
  34.  
  35. var objActive;  // The object which event occured in
  36. var act = 0;    // Flag during the action
  37. var elmH = 0;   // Hue
  38. var elmS = 128; // Saturation
  39. var elmV = 255; // Value
  40. var clrOrg;     // A color before the change
  41. var TimerID;    // Timer ID
  42.  
  43.  
  44. if (document.all) {
  45.     document.onmouseover = doRainbowAnchor;
  46.     document.onmouseout = stopRainbowAnchor;
  47. }
  48. else if (document.getElementById) {
  49.     document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
  50.     document.onmouseover = Mozilla_doRainbowAnchor;
  51.     document.onmouseout = Mozilla_stopRainbowAnchor;
  52. }
  53.  
  54.  
  55. //=============================================================================
  56. // doRainbow
  57. //  This function begins to change a color.
  58. //=============================================================================
  59. function doRainbow(obj)
  60. {
  61.     if (act == 0) {
  62.         act = 1;
  63.         if (obj)
  64.             objActive = obj;
  65.         else
  66.             objActive = event.srcElement;
  67.         clrOrg = objActive.style.color;
  68.         TimerID = setInterval("ChangeColor()",100);
  69.     }
  70. }
  71.  
  72.  
  73. //=============================================================================
  74. // stopRainbow
  75. //  This function stops to change a color.
  76. //=============================================================================
  77. function stopRainbow()
  78. {
  79.     if (act) {
  80.         objActive.style.color = clrOrg;
  81.         clearInterval(TimerID);
  82.         act = 0;
  83.     }
  84. }
  85.  
  86.  
  87. //=============================================================================
  88. // doRainbowAnchor
  89. //  This function begins to change a color. (of a anchor, automatically)
  90. //=============================================================================
  91. function doRainbowAnchor()
  92. {
  93.     if (act == 0) {
  94.         var obj = event.srcElement;
  95.         while (obj.tagName != 'A' && obj.tagName != 'BODY') {
  96.             obj = obj.parentElement;
  97.             if (obj.tagName == 'A' || obj.tagName == 'BODY')
  98.                 break;
  99.         }
  100.  
  101.         if (obj.tagName == 'A' && obj.href != '') {
  102.             objActive = obj;
  103.             act = 1;
  104.             clrOrg = objActive.style.color;
  105.             TimerID = setInterval("ChangeColor()",100);
  106.         }
  107.     }
  108. }
  109.  
  110.  
  111. //=============================================================================
  112. // stopRainbowAnchor
  113. //  This function stops to change a color. (of a anchor, automatically)
  114. //=============================================================================
  115. function stopRainbowAnchor()
  116. {
  117.     if (act) {
  118.         if (objActive.tagName == 'A') {
  119.             objActive.style.color = clrOrg;
  120.             clearInterval(TimerID);
  121.             act = 0;
  122.         }
  123.     }
  124. }
  125.  
  126.  
  127. //=============================================================================
  128. // Mozilla_doRainbowAnchor(for Netscape6 and Mozilla browser)
  129. //  This function begins to change a color. (of a anchor, automatically)
  130. //=============================================================================
  131. function Mozilla_doRainbowAnchor(e)
  132. {
  133.     if (act == 0) {
  134.         obj = e.target;
  135.         while (obj.nodeName != 'A' && obj.nodeName != 'BODY') {
  136.             obj = obj.parentNode;
  137.             if (obj.nodeName == 'A' || obj.nodeName == 'BODY')
  138.                 break;
  139.         }
  140.  
  141.         if (obj.nodeName == 'A' && obj.href != '') {
  142.             objActive = obj;
  143.             act = 1;
  144.             clrOrg = obj.style.color;
  145.             TimerID = setInterval("ChangeColor()",100);
  146.         }
  147.     }
  148. }
  149.  
  150.  
  151. //=============================================================================
  152. // Mozilla_stopRainbowAnchor(for Netscape6 and Mozilla browser)
  153. //  This function stops to change a color. (of a anchor, automatically)
  154. //=============================================================================
  155. function Mozilla_stopRainbowAnchor(e)
  156. {
  157.     if (act) {
  158.         if (objActive.nodeName == 'A') {
  159.             objActive.style.color = clrOrg;
  160.             clearInterval(TimerID);
  161.             act = 0;
  162.         }
  163.     }
  164. }
  165.  
  166.  
  167. //=============================================================================
  168. // Change Color
  169. //  This function changes a color actually.
  170. //=============================================================================
  171. function ChangeColor()
  172. {
  173.     objActive.style.color = makeColor();
  174. }
  175.  
  176.  
  177. //=============================================================================
  178. // makeColor
  179. //  This function makes rainbow colors.
  180. //=============================================================================
  181. function makeColor()
  182. {
  183.     // Don't you think Color Gamut to look like Rainbow?
  184.  
  185.     // HSVtoRGB
  186.     if (elmS == 0) {
  187.         elmR = elmV;    elmG = elmV;    elmB = elmV;
  188.     }
  189.     else {
  190.         t1 = elmV;
  191.         t2 = (255 - elmS) * elmV / 255;
  192.         t3 = elmH % 60;
  193.         t3 = (t1 - t2) * t3 / 60;
  194.  
  195.         if (elmH < 60) {
  196.             elmR = t1;  elmB = t2;  elmG = t2 + t3;
  197.         }
  198.         else if (elmH < 120) {
  199.             elmG = t1;  elmB = t2;  elmR = t1 - t3;
  200.         }
  201.         else if (elmH < 180) {
  202.             elmG = t1;  elmR = t2;  elmB = t2 + t3;
  203.         }
  204.         else if (elmH < 240) {
  205.             elmB = t1;  elmR = t2;  elmG = t1 - t3;
  206.         }
  207.         else if (elmH < 300) {
  208.             elmB = t1;  elmG = t2;  elmR = t2 + t3;
  209.         }
  210.         else if (elmH < 360) {
  211.             elmR = t1;  elmG = t2;  elmB = t1 - t3;
  212.         }
  213.         else {
  214.             elmR = 0;   elmG = 0;   elmB = 0;
  215.         }
  216.     }
  217.  
  218.     elmR = Math.floor(elmR).toString(16);
  219.     elmG = Math.floor(elmG).toString(16);
  220.     elmB = Math.floor(elmB).toString(16);
  221.     if (elmR.length == 1)    elmR = "0" + elmR;
  222.     if (elmG.length == 1)    elmG = "0" + elmG;
  223.     if (elmB.length == 1)    elmB = "0" + elmB;
  224.  
  225.     elmH = elmH + rate;
  226.     if (elmH >= 360)
  227.         elmH = 0;
  228.  
  229.     return '#' + elmR + elmG + elmB;
  230. }
  231.